//添加cookie,默认path为/
function setCookie(key, value, time, path = '/') {
    var date = new Date()
    date.setTime(date.getTime() - 8 * 3600 * 1000 + time * 1000)
    document.cookie = `${key}=${value};expires=${date};path=${path}`
}

//获取cookie
function getCookie(data) {
    var arr = document.cookie.split('; ')
    for (let i = 0; i < arr.length; i++) {
        var brr = arr[i].split('=')
        if (brr[0] === data) {
            return brr[1]
        }
    }
    //或者用正则
    // var reg = /([^; =]+)=([^;]+)/g;
    // do {
    //     var arr = reg.exec(document.cookie)
    //     if (arr && arr[1] === key) {
    //         return arr[2]
    //     }
    // } while (arr)
}
//删除cookie,设置有效期为:已超过1秒
function removeCookie(data, path = '/') {
    setCookie(data, null, -1, path)
}